﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


class LinqForStudentsTest
{
    static void Main(string[] args)
    {
        var studentsList = new[] 
        { 
            new {firstName = "Kamen", lastname = "Ivanov", age = 20},
            new {firstName = "Alexander", lastname = "Ivanov", age = 16},
            new {firstName = "Ivan", lastname = "Dimitrov", age = 20},
            new {firstName = "Petyr", lastname = "Stoimenov", age = 22},
            new {firstName = "Petyr", lastname = "Angelov", age = 22},
            new {firstName = "Georgi", lastname = "Mihajlov", age = 26},
        };

        var names =
            from student in studentsList
            where student.firstName.CompareTo(student.lastname) == -1
            select student;            
        
        foreach (var item in names)
        {
            Console.WriteLine(item);
        }
        Console.WriteLine();

        var namesByAge =
            from student in studentsList
            where (student.age >= 18 && student.age <= 24)
            select new { student.firstName, student.lastname };

        foreach (var item in namesByAge)
        {
            Console.WriteLine(item);
        }
        Console.WriteLine();

        var sortedStudents = studentsList.OrderByDescending(student => student.firstName).
            ThenByDescending(student => student.lastname);
        foreach (var item in sortedStudents)
        {
            Console.WriteLine(item);
        }
        Console.WriteLine();

        int[] numbers = { 2, 4, 5, 7, 3, 14, 21, 4, 6, 7, 6, 4, 13, 30, 42 };

        var devidibleNumbersLambda = numbers.Where((number) => 
            {
                return (number % 7 == 0) || (number % 3 == 0);
            });
        foreach (int item in devidibleNumbersLambda)
        {
            Console.WriteLine(item);
        }
        Console.WriteLine();

        var devidibleNumbersLinq =
            from number in numbers
            where (number % 7 == 0) || (number % 3 == 0)
            select number;

        foreach (var item in devidibleNumbersLinq)
        {
            Console.WriteLine(item);
        }
        Console.WriteLine();
    }
}

